/****************************************************************
 *  This file created by writerB.php on 03/20/2007 at 23:02:49  *
 ****************************************************************
 *  writerB.php created by Tonk (tonk@ctonk.com) in 2007        *
 ****************************************************************
 *                 General Document Information
 *
 *  File Name: note.cpp
 *  Class Name: Note
 *  Data members: 8
 *  Notes:
 ****************************************************************/

#include <iostream>
#include "note.h"
#include "stringutil.h"



int Note::numNotes = 0;
int Note::noteIndex = 0;


// Default constructor...
Note::Note() {
	setNoteID( ++noteIndex );
	setId( 0 );
	setPid( 0 );
	// Increment the object count...
	numNotes++;
}

// Additional constructors...

// Copy constructor (Doesn't change _NoteID)...
Note::Note( const Note& ref ) {
	setNoteID( ++noteIndex );
	setId( ref.getId() );
	setPid( ref.getPid() );
	setBoard( ref.getBoard() );
	setAuthor( ref.getAuthor() );
	setRecipient( ref.getRecipient() );
	setSubject( ref.getSubject() );
	setBody( ref.getBody() );
	setSent( ref.getSent() );
	// Increment the object count...
	numNotes++;
}

// Destructor...
Note::~Note() {
	// Decrement the object count...
	numNotes--;
}

// Assignment operator (Doesn't change _NoteID)...
Note& Note::operator = ( const Note& ref ) {
	setId( ref.getId() );
	setPid( ref.getPid() );
	setBoard( ref.getBoard() );
	setAuthor( ref.getAuthor() );
	setRecipient( ref.getRecipient() );
	setSubject( ref.getSubject() );
	setBody( ref.getBody() );
	setSent( ref.getSent() );
	return *this;
}

// Equality operator (Doesn't compare _NoteID)...
bool Note::operator == ( const Note& ref ) const {
	return	(
		   getId() == ref.getId()
		&& getPid() == ref.getPid()
		&& getBoard() == ref.getBoard()
		&& getAuthor() == ref.getAuthor()
		&& getRecipient() == ref.getRecipient()
		&& getSubject() == ref.getSubject()
		&& getBody() == ref.getBody()
		&& getSent() == ref.getSent()
		);
}

// Less than operator (Compares _NoteID)...
bool Note::operator < ( const Note& ref ) const {
	return ( getNoteID() < ref.getNoteID() );
}

// Greater than operator (Compares _NoteID)...
bool Note::operator > ( const Note& ref ) const {
	return ( getNoteID() > ref.getNoteID() );
}

// Protected Methods...
void Note::setNoteID( const int& NoteID ) {
	_NoteID = NoteID;
}

// Public accessor methods...
int Note::getNoteID( void ) const {
	return _NoteID;
}

void Note::setId( const unsigned& id ) {
	_id = id;
	return;
}

unsigned Note::getId( void ) const {
	return _id;
}

void Note::setPid( const unsigned& pid ) {
	_pid = pid;
	return;
}

unsigned Note::getPid( void ) const {
	return _pid;
}

void Note::setBoard( const std::string& board ) {
	_board = board;
	return;
}

std::string Note::getBoard( void ) const {
	return _board;
}

void Note::setAuthor( const std::string& author ) {
	_author = author;
	return;
}

std::string Note::getAuthor( void ) const {
	return _author;
}

void Note::setRecipient( const std::string& recipient ) {
	_recipient = recipient;
	return;
}

std::string Note::getRecipient( void ) const {
	return _recipient;
}

void Note::setSubject( const std::string& subject ) {
	_subject = subject;
	return;
}

std::string Note::getSubject( void ) const {
	return _subject;
}

void Note::setBody( const std::string& body ) {
	_body = body;
	return;
}

std::string Note::getBody( void ) const {
	return _body;
}

std::string* Note::getBodyP( void ) {
	return &_body;
}

void Note::setSent( const std::string& sent ) {
	_sent = sent;
	return;
}

std::string Note::getSent( void ) const {
	return _sent;
}

// General methods...

// Static methods...

// Associated operators...
std::ostream& operator << ( std::ostream& write, Note& note ) {
	write << "\n**NOTE\n";
	write << note.getId() << ' ' << note.getPid() << '\n';
	write << note.getBoard() << '\n';
	write << note.getAuthor() << '\n';
	write << note.getRecipient() << '\n';
	write << note.getSubject() << '\n';
	write << note.getSent() << '\n';
	write << note.getBody() << "$\n";
	return write;
}

std::ostream& operator << ( std::ostream& write, Note* note ) {
	return ( write << *note );
}

std::istream& operator >> ( std::istream& read, Note& note ) {
	int itmp = 0;
	char ctmp[100000];

	read >> itmp;
	note.setId( itmp );
	read >> itmp;
	note.setPid( itmp );
	read.get();
	read.getline( ctmp, 100000 );
	note.setBoard( std::string(ctmp) );
	read.getline( ctmp, 100000 );
	note.setAuthor( std::string(ctmp) );
	read.getline( ctmp, 100000 );
	note.setRecipient( std::string(ctmp) );
	read.getline( ctmp, 100000 );
	note.setSubject( std::string(ctmp) );
	read.getline( ctmp, 100000 );
	note.setSent( std::string(ctmp) );
	read.getline( ctmp, 100000, '$' );
	note.setBody( std::string(ctmp) );

	return read;
}

std::istream& operator >> ( std::istream& read, Note* note ) {
	return ( read >> *note );
}
